import os

def replace_specific_characters(folder_path, old_character, new_character):
    image_extensions = ['.jpg', '.jpeg', '.png']
    
    for subfolder in os.listdir(folder_path):
        subfolder_path = os.path.join(folder_path, subfolder)
        if os.path.isdir(subfolder_path):
            for filename in os.listdir(subfolder_path):
                file_extension = os.path.splitext(filename)[1].lower()
                if file_extension in image_extensions:
                    try:
                        new_filename = filename.replace(old_character, new_character)
                        old_file_path = os.path.join(subfolder_path, filename)
                        new_file_path = os.path.join(subfolder_path, new_filename)
                        os.rename(old_file_path, new_file_path)
                    except Exception as e:
                        print(f"无法处理文件 {filename}: {e}")

folder_path = r'20230815'
old_character = '20230815'
new_character = '20230815_2'
replace_specific_characters(folder_path, old_character, new_character)
print("照片文件名替换完毕！")
